﻿@using LunwenYun.Infrastructure.Entities.Entity;
@using LunwenYun.Infrastructure.Entities.Enum;
@{
    Layout = "~/Views/Shared/_m_Main.cshtml";
    User user = new User().Find(HttpContext.Current.User.Identity.Name);
}
<div class="container">
    <div style="display: none;">
        <form id="form1" action="/m/option" method="post">
        <input id="hidtoken" type="hidden" name="Token" />
        <input id="hidOptionType" type="hidden" name="OptionType" />
        <input id="hidId" type="hidden" name="Id" />
        </form>
    </div>
    <div class="row">
        <div class="span3">
            <ul class="nav nav-tabs nav-stacked">
                <li class="active"><a href="/m/authorcenter"><i class="icon-user"></i><strong>个人中心</strong></a></li>
                <li><a href="/m/authorcenter">我的投稿</a></li>
                <li class="active"><a href="/m/myorders">我的约稿
                    @if (ViewBag.OrderCount > 0)
                    {
                        <span class="badge badge-warning">@ViewBag.OrderCount</span>
                    }</a></li>
                <li><a href="/m/resetpassword">修改密码</a></li>
            </ul>
        </div>
        <div class="span9">
            <blockquote>
                <p>
                    <strong>我的约稿</strong></p>
            </blockquote>
            <hr />
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>
                            稿件
                        </th>
                        <th style="width: 15%">
                            约稿人
                        </th>
                        <th style="width: 15%">
                            状态
                        </th>
                        <th style="width: 8%">
                            预算
                        </th>
                        <th style="width: 25%">
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @{ItemListBox<Trade> list = ViewBag.Orders;
                      if (list != null && list.Data != null && list.Data.Any())
                      {
                          foreach (var item in list.Data)
                          {
                        <tr>
                            <td>
                            @if(item.Organization==0)
                            {
                                @(item.Article != null ? item.Article.Title : item.Periodical != null ? item.Periodical.Name + "投稿" : "")
                            }
                            else
                            {
                                @item.IndustryOrganization.IndustryName <span>[行业投稿]</span>
                            }
                            </td>
                            <td>
                            @if(item.Organization==0)
                            {
                                @item.AgentInfo.Name
                            }
                            else
                            {
                                @item.IndustryOrganization.OrganizationName
                            }
                            </td>
                            <td>
                                @switch (item.Status)
                                {
                                    default:
                                    case TradeStatus.Open:
                                    case TradeStatus.Execute:
                                    case TradeStatus.TradeConfirm_o:
                                    <span class="label label-info"><b>@item.Status.Mapping()</b> </span>
                                                                 break;
                                    case TradeStatus.Pay:
                                    case TradeStatus.WaitPay:
                                    <span class="label label-warning"><b>@item.Status.Mapping()</b> </span>   
                                                                    break;
                                    case TradeStatus.TradeIsConfirm:
                                    case TradeStatus.Trading:
                                    <span class="label label-success"><b>@item.Status.Mapping()</b> </span> 
                                                                    break;
                                    case TradeStatus.Cancel:
                                    <span class="label"><b>@item.Status.Mapping()</b></span>
                                                      break;
                                    case TradeStatus.Dispute:
                                    <span class="label label-important"><b>@item.Status.Mapping()</b></span>
                                                                      break;
                                }
                            </td>
                            <td>@((int)item.Momey)
                            </td>
                            <td>
                                <a href="javascript:;" onclick="opendetail(this)" class="btn btn-mini">详情</a>
                                <div class="btn-group btn-mini">
                                    @switch (item.Status)
                                    {
                                        case TradeStatus.Open:
                                            if (item.OpenUsername.ToLower() != HttpContext.Current.User.Identity.Name.ToLower())
                                            {
                                        <button class="btn btn-primary btn-mini" onclick="acceptorder(@item.Id,'@item.Token')">
                                            接收</button>        
                                        <button data-toggle="dropdown" class="btn btn-primary btn-mini dropdown-toggle">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu">
                                            <li><a href="javascript:;" onclick="refuseorder(@item.Id,'@item.Token')">取消</a></li>
                                            <li><a href="javascript:;" onclick="deleteorder(@item.Id,'@item.Token')">删除</a></li>
                                        </ul>
                                            }
                                            else
                                            {
                                        <button class="btn btn-primary btn-mini" onclick="refuseorder(@item.Id,'@item.Token')">
                                            取消</button>        
                                        <button data-toggle="dropdown" class="btn btn-primary btn-mini dropdown-toggle">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu">
                                            <li><a href="javascript:;" onclick="deleteorder(@item.Id,'@item.Token')">删除</a></li>
                                        </ul>
                                            }
                                            break;
                                        case TradeStatus.WaitPay:
                                        <a class="btn btn-primary btn-mini" target="_blank" href="/pay/choose?trade=@item.Id&token=@(LunwenYun.Tool.Framework.EncodeByBase64.Encode(item.Token))">
                                            支付</a> 
                                        <button data-toggle="dropdown" class="btn btn-primary btn-mini dropdown-toggle">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu">
                                            <li><a href="javascript:;" onclick="refuseorder(@item.Id,'@item.Token')">取消</a></li>
                                            <li><a href="javascript:;" onclick="deleteorder(@item.Id,'@item.Token')">删除</a></li>
                                        </ul> 
                                                                                                 break;
                                        case TradeStatus.Cancel:
                                        <button class="btn btn-primary btn-mini" onclick="deleteorder(@item.Id,'@item.Token')">
                                            删除</button>
                                                                                                           break;

                                        case TradeStatus.Dispute:
                                        <span class="label label-important"><b><a style="text-decoration:none;" href="/home/consumerservice">请联系管理员</a></b></span>
                                                                                                           break;
                                        case TradeStatus.Pay:
                                        <span class="label label-warning">待约稿人</span>
                                                                                                           break;
                                        case TradeStatus.Execute:
                                        if (item.LastModify.AddDays(7) < DateTime.Now)
                                        {
                                        <button class="btn btn-primary btn-mini" onclick="ispublish(@item.Id,'@item.Token')">
                                            确认已发表</button>  
                                        <button data-toggle="dropdown" class="btn btn-primary btn-mini dropdown-toggle">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu">
                                            <li><a href="/home/consumerservice">其他问题，请联系管理员</a></li>
                                        </ul>
                                        }
                                                                                                           break;
                                        case TradeStatus.TradeConfirm_o:
                                        <button class="btn btn-primary btn-mini" onclick="ispublish(@item.Id,'@item.Token')">
                                            确认已发表</button> 
                                        <button data-toggle="dropdown" class="btn btn-primary btn-mini dropdown-toggle">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu">
                                            <li><a href="javascript:;" onclick="deferred(@item.Id,'@item.Token')">延长时限</a></li>
                                            <li><a href="javascript:;" onclick="dispute(@item.Id,'@item.Token')">存在争议</a></li>
                                        </ul>
                                                                                             break;
                                    }
                                </div>
                            </td>
                        </tr>
                        <tr style="display: none;">
                            <td colspan="5">@Html.Raw(item.Description)
                                <br />
                                <p>
                                    预算金额：<b>@((int)item.Momey)</b></p>
                                <p>
                                @if(item.Organization != 0)
                                {
                                    <span>如有疑问，请联系：</span><a href="/j/@item.IndustryOrganization.IndustryCode">@item.IndustryOrganization.OrganizationName</a>
                                }
                                else
                                {
                                    <div>联系约稿人：<a target="_blank" href="http://wpa.qq.com/msgrd?v=3&amp;uin=@item.AgentInfo.QQ&amp;site=qq&amp;menu=yes">
                                        <img border="0" src="http://wpa.qq.com/pa?p=2:@item.AgentInfo.QQ:41" alt="点击这里给我发消息" title="点击这里给我发消息" />
                                    </a>
                                    </div>
                                }
                                </p>
                                @if(item.Status == TradeStatus.TradeConfirm_o)
                                {
                                    <p>
                                        约稿人于 @item.ConfirmTradeDate.ToString("yyyy/MM/dd HH:mm") 确认改稿件已发表，请认真检查确认论文是否已经按照约定成功发表，如有疑问请尽快与约稿人取得联系或要求<a target="_blank" href="/home/consumerservice">客服介入</a>。
                                        如果您在 <b style="color:#f00;">@item.ConfirmExpireDate.ToString("yyyy/MM/dd 23:59")</b> 后任未确认，系统将自动确认本次约稿完成。另外，您也可以<b>延长本次约稿时限</b>。
                                    </p>
                                }
                            </td>
                        </tr>
                          }
                      }}
                </tbody>
            </table>
        </div>
    </div>
</div>
@section tail
{
    <script type="text/javascript">
        $(function () {
            $('#licenter').addClass('active');
        });
        function opendetail(sender) {
            $(sender).parent().parent().next('tr').toggle();
        }
        function dispute(id, token) {
            if (confirm('建议先与约稿人进行沟通，您确认此次论文投稿出现争议吗？')) {
                $('#hidOptionType').val(5);
                $('#hidId').val(id);
                $('#hidtoken').val(token);
                $('#form1').submit();
            }
        }
        function deferred(id, token) {
            if (confirm('建议请与约稿人取得联系以确定是否需要延长时限。您确定要延长时限吗？')) {
                $('#hidOptionType').val(4);
                $('#hidId').val(id);
                $('#hidtoken').val(token);
                $('#form1').submit();
            }
        }
        function ispublish(id, token) {
            if (confirm('您确定您的论文已经成功发表了吗？您确定以后稿费将在3个工作日内转入约稿人账户。如果您的论文还未成功发表，请不要确认！')) {
                $('#hidOptionType').val(3);
                $('#hidId').val(id);
                $('#hidtoken').val(token);
                $('#form1').submit();
            }
        }
        function acceptorder(id, token) {
            if (confirm('您确定接收此次约稿吗？')) {
                $('#hidOptionType').val(1);
                $('#hidId').val(id);
                $('#hidtoken').val(token);
                $('#form1').submit();
            }
        }
        function refuseorder(id, token) {
            if (confirm('您确定取消此次约稿吗？')) {
                $('#hidOptionType').val(2);
                $('#hidId').val(id);
                $('#hidtoken').val(token);
                $('#form1').submit();
            }
        }
        function deleteorder(id, token) {
            if (confirm('您确定删除此约稿信息吗？')) {
                $('#hidOptionType').val(9);
                $('#hidId').val(id);
                $('#hidtoken').val(token);
                $('#form1').submit();
            }
        }
    </script>
}
